<?php
include_once dirname(dirname(dirname(__FILE__))).'/include/db_connect.php';

function getProductionsRuleId() {
	$conn = get_db_conn();
	$sql = 'select id from productions_rule limit 0,1';
	$result = mysql_query($sql,$conn) or die("db error");
	if(mysql_num_rows($result)==0) {
		$sql = 'insert into productions_rule(update_time) values("'.date('Y-m-d H:i:s').'");';
		mysql_query($sql,$conn) or die("db error");
		$sql = 'select id from aid_rule limit 0,1';
		$result = mysql_query($sql,$conn) or die("db error");
	}
	$row = mysql_fetch_array($result);
	return $row['id'];
}

function updateProductionsRule($content,$user_id) {
	$conn = get_db_conn();
	$sql = 'update productions_rule set content = "'.$content.'" ,author_id = '.$user_id.
			',update_time = "'.date('Y-m-d H:i:s').'" where id = '.getProductionsRuleId().';';
	mysql_query($sql,$conn) or die("db error");
	return true;
}

function getProductionsRule() {
	$conn = get_db_conn();
	$id = getProductionsRuleId();
	$sql = 'select * from productions_rule where id = '.$id.' limit 0,1;';
	$result = mysql_query($sql,$conn) or die("db error");
	$row = mysql_fetch_array($result);
	return $row;
}
function getProductionsApplyInfo(){
	$conn = get_db_conn();
	$sql = 'select aa.*,aac.dir,aac.store_name,su.username,su.id as s_user_id from productions_apply aa left join productions_accessory aac on aa.id=aac.productions_apply_id left join s_user su on aa.s_user_id=su.id';
	$result = mysql_query($sql,$conn) or die("db error");
	return $result;

}


function  getSUserById($id){
	$conn = get_db_conn();
	$sql = "select * from s_user where id='".$id."' limit 0,1;";
	$ret = mysql_query($sql,$conn);
	if ($ret) {
		mysql_close($conn);
		return $ret;
	}else {
		echo "error: ".mysql_error();
		mysql_close($conn);
		return false;
	}


}
?>